package com.zimmur.app.mocolink.manage.web.quartz;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import com.zimmur.app.mocolink.domain.apiData.GoodsData;
import com.zimmur.app.mocolink.domain.util.DateUtils;
import com.zimmur.app.mocolink.manage.web.vogData.TakeGoods;
import com.zimmur.app.mocolink.service.IGoodsService;
import com.zimmur.app.mocolink.service.RedisCacheUtil;
@Component
public class ProcessUpdateGoods {
	@Autowired
	private RedisCacheUtil<Integer> redisCacheUtil;
	@Autowired
	private IGoodsService goodsService;
	private static final String key="mocolink_takeGoods_time";
	
	/**
     * 每隔五分钟执行一次
     * @Scheduled(fixedRate = 5*60*1000) 
     */
	@Scheduled(fixedRate=5*60*1000)
	public void handleUserPushMessage(){
		boolean exist = redisCacheUtil.exists(key);
		Integer timestamp;
		if(exist){
			timestamp=redisCacheUtil.getCacheObject(key);
		}else{
			timestamp=0;
		}
		
		List<GoodsData> goodsDatas=TakeGoods.getGoods(timestamp);
		if(goodsDatas.size()>0){
			int flag = goodsService.savePushData(goodsDatas);
			if(flag>0){
				//更新时间
				int time=DateUtils.getNowUnixTime()-60;
				redisCacheUtil.setCacheObject(key, time);
			}
		}
		
	}
}
